<!-- 职级编辑弹窗 -->
<template>
    <el-dialog
      :title="isUpdate?'查看发送日志':'查看发送日志'"
      :visible="visible"
      width="90%"
      :destroy-on-close="true"
      :lock-scroll="false"
      @open="loaddata"
      @update:visible="updateVisible">
      
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        height="calc(100vh - 415px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar" v-if="false">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit(null)"
            >NC回写
          </el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            class="ele-btn-icon"
            @click="removeBatch"
            v-if="false"
            >删除
          </el-button>
        </template>
        <template slot="submitNo" slot-scope="{row}">
          <div style="white-space:pre-wrap">{{ row.submitNo }}</div>
        </template>
        <template slot="submitTime" slot-scope="{row}">
          <div style="white-space:pre-wrap">{{ row.submitTime }}</div>
        </template>
        <template slot="reqBody" slot-scope="{row}">
          <el-input type="textarea" :rows="4" :value="row.requestBody"></el-input>
        </template>
        <template slot="resBody" slot-scope="{row}">
          <el-input type="textarea" :rows="4" :value="row.responseBody"></el-input>
        </template>
        <template slot="resResult" slot-scope="{row}">
          <el-input type="textarea" :rows="4" :value="row.responseResult"></el-input>
        </template>
      </ele-pro-table>

      <div slot="footer">
        <el-button @click="updateVisible(false)">关闭</el-button>
        <el-button v-if="false"
          type="primary"
          @click="save"
          >保存
        </el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  export default {
    name: 'IbpLogList',
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      dataItem: Object
    },
    data() {
      return {
        // 表单数据
        //form: Object.assign({status: 1}, this.dataItem),
        url: '/bipservicelog/index',
      // 表格列配置
      columns: [
        // {
        //   columnKey: 'selection',
        //   type: 'selection',
        //   width: 45,
        //   align: 'center',
        //   fixed: "left"
        // },
        {
          prop: 'submitNo',
          label: 'ID_物料编号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
          slot:'submitNo'
        },
        {
          prop: 'requestBody',
          label: '提交报文',
          showOverflowTooltip: true,
          minWidth: 400,
          align: 'center',
          slot:'reqBody'
        },
        {
          prop: 'responseBody',
          label: '返回结果',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
          slot:'resBody'
        },
        {
          prop: 'responseCode',
          label: '返回状态',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center'
        },
        {
          prop: 'responseResult',
          label: '处理结果',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
          slot:'resResult'
        },
        {
          prop: 'submitTime',
          label: '提交时间',
          showOverflowTooltip: true,
          minWidth: 70,
          align: 'center',
          slot:'submitTime'
        },

      ],
      // 表格搜索条件
      where: {danjNo:this.dataItem?this.dataItem.danjNo:''},

        // 表单验证规则
        rules: {
          name: [
            {required: true, message: '请输入职级名称', trigger: 'blur'}
          ],
          status: [
            {required: true, message: '请选择职级状态', trigger: 'blur'}
          ],
          sort: [
            {required: true, message: '请输入排序号', trigger: 'blur'}
          ]
        },
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false
      };
    },
    watch: {
      data() {
        if (this.dataItem) {
          this.form = Object.assign({}, this.dataItem);
          this.isUpdate = true;
        } else {
          this.form = {};
          this.isUpdate = false;
        }
      }
    },
    methods: {
      loaddata(){
        if (this.dataItem) {
          this.where.bid = this.dataItem.id;
          this.$refs.table.reload();
        }        
      },
      /* 保存编辑 */
      save() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.loading = true;
            this.$http[this.isUpdate ? 'put' : 'post'](this.isUpdate ? '/level/edit' : '/level/add', this.form).then(res => {
              this.loading = false;
              if (res.data.code === 0) {
                this.$message.success(res.data.msg);
                if (!this.isUpdate) {
                  this.form = {};
                }
                this.updateVisible(false);
                this.$emit('done');
              } else {
                this.$message.error(res.data.msg);
              }
            }).catch(e => {
              this.loading = false;
              this.$message.error(e.message);
            });
          } else {
            return false;
          }
        });
      },
      /* 更新visible */
      updateVisible(value) {
        this.$emit('update:visible', value);
      }
    }
  }
  </script>
  
  <style scoped>
  .el-table .cell {
  white-space: pre-wrap;   /*这是重点。文本换行*/
}
  </style>
  